import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * An enemy that spits fire after it gets to a certain position.
 * 
 * @author Manuel Nava
 * @version 1.0
 */
public class Snake extends Enemy
{
    private int contMov;
    private int contAttack;
    private GreenfootImage stand;
    private GreenfootImage attack1;
    private GreenfootImage attack2;
    
    /**
     * Constructor of the class snake, set counters to zero and loads the images that the snake will
     * take.
     */
    public Snake()
    {
        contMov=0;
        contAttack=0;
        stand=new GreenfootImage("snake-stand.png");
        attack1=new GreenfootImage("snake-attack1.png");
        attack2=new GreenfootImage("snake-attack2.png");
    }
    
    /**
     *The method act calls the superclass methods move and death, also set the counters to the 
     *movements to attack and add object of the class fire after certain time.
     */
    public void act() 
    {
        
        super.move();
        super.death();
        if(super.getIsDeath()==true) return;
        if(getX()==450&&contAttack<=0)
           {
               attack();
               contAttack=2000;
            }
        if(contAttack>0)
            contAttack--;
        if(contMov>0)
           if(contMov==20)
           {
             setImage(attack2);
             getWorld().addObject(new Fire(),getX()-45,getY());
            }
        if(contMov==0)
           setImage(stand);
        if(contMov>0)
            contMov--;
        
    }  
   
    /**
     * Sets the image the snake will take when is attacking.
     */
    public void attack()
    {
        contMov=40;
        setImage(attack1);
    }
    
}
